/*
 * PanelUser.java   J2RS - Jordi Sanchez
 *
 * Created on 08-dic-2011, 17:20:12
 */
package edu.uoc.tdp.client;

import edu.uoc.tdp.i18n.TDPLanguageUtils;
import edu.uoc.tdp.i18n.TDPLanguageConstants;
import edu.uoc.tdp.dal.ManagementUsers;
import edu.uoc.tdp.entity.Rol;
import edu.uoc.tdp.entity.User;
import edu.uoc.tdp.customException.EIssueException;
import java.awt.Color;
import java.rmi.RemoteException;
import java.util.List;
import java.util.MissingResourceException;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import java.util.logging.Logger;
import java.util.logging.Level;
import javax.swing.table.AbstractTableModel;
import java.util.Date;
import java.util.Arrays;
import java.text.*;

/**
 *
 * @author J2RS - Jordi Sanchez
 */
public class PanelUser extends javax.swing.JFrame {

    //private ManagementUsers remoto;
    private final String url = new String("rmi://localhost/eEspais");
    private Boolean NewUser = false;
    public User UsuarioTrabajo = null;
    public String UsuarioActivo=null;

    /** Creates new form PanelUser */
    public PanelUser(Boolean Admin) throws RemoteException, edu.uoc.tdp.common.EIssueException {

        initComponents();

        // Carregar texts de labels i botons               
        String txt=null;
        txt=TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_TITLE);
        this.setTitle(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_TITLE));
        this.setTitle(TDPLanguageUtils.getMessage("Client.Users.Title"));
        lblUserId.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLUSERID));
        lblPassword.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLPASSWORD));
        lblName.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLNAME));
        lblSurname1.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLSURNAME1));
        lblSurname2.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLSURNAME2));
        lblCompany.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLCOMPANY));
        lblAddress.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLADDRESS));
        lblPostalCode.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLZIPCODE));
        lblCity.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLCITY));
        lblTelephone.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLTELEPH));
        //lblMobile.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLMOBILE));
        lblRoleId.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLROLEID));
        lblEmail.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLEMAIL));
        lblFind1.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLFIND1));
        //cbFind1.(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNSAVE));     
        lblFindValue.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLFINDVALUE));
        //btnFind.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNFIND));     
        btnNew.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNNEW));
        btnModif.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNMODIF));
        btnDelete.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNDELETE));
        btnSave.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNSAVE));
        btnCancel.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNCANCEL));
        //btnChangePw.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNCHANGEPW));
        btnChange.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNCHANGE));
        //btnBack.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNBACK));
        
        
        //Deshabilitem els texts
        EnableObjects(false);
        ObjectsStartStatus();

        // Omplim dades combo Rols
        try {
            //remoto = new ManagementUsers();
            List<Rol> listaRoles = Client.remoteMaintenance.GetAllRoles();
            cargarComboRoles(cbRoles, listaRoles);
		} catch (RemoteException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
		}   

        //Omplim Grid
        cargarGrid();

        
        //Usuari actiu
        try{        
            UsuarioActivo=Client.availableUser.getName();
            if (UsuarioActivo=="" || UsuarioActivo==null) {
                UsuarioActivo="UNKNOWN";
            }            
        }
        catch(Exception e){
             Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, e);
             UsuarioActivo="UNKNOWN";
        }   
        finally{
            lblUser.setText(UsuarioActivo);
        }

        
    }

    /*
     * Carga la lista que se le envía por parámetro en el combo del parámetro
     */
    private void cargarComboRoles(JComboBox combo, List lista) {
        String item;
        for (Object obj : lista) {
            item = ((Rol) obj).getRolleId() + " " + ((Rol) obj).getRolleDescription();
            combo.addItem(item);
        }
    }

    /*
     * Carga la lista que se le envía por parámetro en el combo del parámetro
     */
    private void cargarGrid() {
        //Table Usuers per busquedes
        try {
            //remoto = new ManagementUsers();
            List<User> UsersList = Client.remoteMaintenance.GetAllUserTable();
            //set the entity objects in the list
            TableModelUser model = new TableModelUser(UsersList);
            tblUsers.setModel(model);
            tblUsers.getRowSelectionAllowed();
        } catch (RemoteException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    /***************************************************************************
     *  Procediment per habilitar/dehabilitar objectes
     ****************************************************************************/
    private void ObjectsStartStatus() {
        //habilitem els objectes texts per a l'entrada de dadaes
        EnableObjects(false);
        //Netejem objectes de txt
        CleanTxt();
        NewUser = false;
        btnNew.setEnabled(true);
        btnModif.setEnabled(false);
        btnDelete.setEnabled(false);
        btnChangePw.setEnabled(false);
        btnSave.setEnabled(false);
        btnCancel.setEnabled(false);
        btnBack.setEnabled(true);
        tblUsers.setEnabled(true);
        btnChange.setVisible(false);
        txtInactivDate.setVisible(false);
        txtInactivUs.setVisible(false);
        lblIncactive.setVisible(false);
        txtUserId.setBackground(Color.white);
        txtName.setBackground(Color.white);
        txtZipCode.setBackground(Color.white);
        txtEmail.setBackground(Color.white);
        
        //Només Administrador pot buscar
        if (Client.availableUser.getRoleId()==2){
            btnFind.setEnabled(true);
            cbFind1.setEnabled(true);
        }
        else
        {
            btnFind.setEnabled(false);
            cbFind1.setEnabled(false);
        }
    }

    /***************************************************************************
     *  Procediment per habilitar/dehabilitar objectes
     ****************************************************************************/
    private void EnableObjects(Boolean EnableObj) {
        txtUserId.setEnabled(EnableObj);
        txtName.setEnabled(EnableObj);
        txtPassword1.setEnabled(EnableObj);
        txtPassword2.setEnabled(EnableObj);
        txtSurname1.setEnabled(EnableObj);
        txtSurname2.setEnabled(EnableObj);
        txtAddress.setEnabled(EnableObj);
        txtCity.setEnabled(EnableObj);
        txtCompany.setEnabled(EnableObj);
        txtEmail.setEnabled(EnableObj);
        //txtFindValue.setEnabled(EnableObj);
        txtMobile.setEnabled(EnableObj);
        txtTelephone.setEnabled(EnableObj);
        txtZipCode.setEnabled(EnableObj);
        cbRoles.setEnabled(EnableObj);
    }

    /***************************************************************************
     *   Proceciment per netejar les caselles de text
     ****************************************************************************/
    private void CleanTxt() {
        txtUserId.setText("");
        txtName.setText("");
        txtPassword1.setText("");
        txtPassword2.setText("");
        txtSurname1.setText("");
        txtSurname2.setText("");
        txtAddress.setText("");
        txtCity.setText("");
        txtCompany.setText("");
        txtEmail.setText("");
        txtFindValue.setText("");
        txtMobile.setText("");
        txtTelephone.setText("");
        txtZipCode.setText("");
    }

    /***************************************************************************
     *   BTN - Buscar Usuaris / Filtre
     ****************************************************************************/
 private void btnFindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindActionPerformed
        //Table Usuers per busquedes
        try {
            
            if (txtFindValue.getText().length() == 0) {
                //Omplim Grid amb tots els 
                cargarGrid();
            }
            else{           
                Integer indx = cbFind1.getSelectedIndex();
                //remoto = new ManagementUsers();
                List<User> UsersList=null;

                switch(indx){
                    case 0: 
                        UsersList = Client.remoteMaintenance.GetUse_FindById(txtFindValue.getText());
                        break;                    
                    case 1: 
                        UsersList = Client.remoteMaintenance.GetUse_FindByPostalCode(Integer.parseInt(txtFindValue.getText()));
                        break;    		
                    case 2: 
                        UsersList = Client.remoteMaintenance.GetUse_FindByName(txtFindValue.getText());
                        break;    		                    
                    case 3: 
                        UsersList = Client.remoteMaintenance.GetUse_FindByCompany(txtFindValue.getText());
                        break;    		                                            
                }

                TableModelUser model = new TableModelUser(UsersList);
                tblUsers.setModel(model);
                tblUsers.getRowSelectionAllowed();
            }
        } catch (RemoteException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        }      
    }//GEN-LAST:event_btnFindActionPerformed

 


private void ShowUser(String UserId) throws RemoteException, edu.uoc.tdp.common.EIssueException{
    //Table Usuers per busquedes
    try {

        if (UserId.length() > 0) {
            //remoto = new ManagementUsers();
            List<User> UsersList=null;
            UsersList = Client.remoteMaintenance.GetUserById(UserId);
            User UserActiu = UsersList.get(0);
            txtUserId.setText(UserActiu.getUserId());
            txtName.setText(UserActiu.getName());
            txtPassword1.setText(UserActiu.getPassword());
            txtPassword2.setText(UserActiu.getPassword());
            txtSurname1.setText(UserActiu.getSurname1());
            txtSurname2.setText(UserActiu.getSurname2());
            txtAddress.setText(UserActiu.getAddress());
            txtCity.setText(UserActiu.getCity());
            txtCompany.setText(UserActiu.getCompany());
            txtEmail.setText(UserActiu.getEmail());
            txtMobile.setText(String.valueOf(UserActiu.getMobilePhone()));
            txtTelephone.setText(String.valueOf(UserActiu.getTelephone()));
            txtZipCode.setText(String.valueOf(UserActiu.getPostalCode()));
            cbRoles.setSelectedIndex(UserActiu.getRoleId());
            btnModif.setEnabled(true);
            btnDelete.setEnabled(true);
            btnChangePw.setEnabled(true);
            
            //Eliminem espais del string. Ho fem aqui pq el Trim si no hi ha res dona error!?!?
            if (txtUserId.getText().length() > 0) { txtUserId.setText(txtUserId.getText().trim());}
            if (txtName.getText().length() > 0) { txtName.setText(txtName.getText().trim());}
            if (txtSurname1.getText().length() > 0) { txtSurname1.setText(txtSurname1.getText().trim());}
            if (txtSurname2.getText().length() > 0) { txtSurname2.setText(txtSurname2.getText().trim());}
            if (txtAddress.getText().length() > 0) { txtAddress.setText(txtAddress.getText().trim());}
            if (txtCity.getText().length() > 0) { txtCity.setText(txtCity.getText().trim());}
            if (txtCompany.getText().length() > 0) { txtCompany.setText(txtCompany.getText().trim());}
            if (txtEmail.getText().length() > 0) { txtEmail.setText(txtEmail.getText().trim());}
            
            
            String InactUser=null;
            InactUser=UserActiu.getInactivationUser();
            
            if (InactUser==null || InactUser=="")
            {
                txtInactivDate.setVisible(false);
                txtInactivUs.setVisible(false);
                lblIncactive.setVisible(false);
                btnModif.setEnabled(true);
                btnDelete.setEnabled(true);     
                btnChangePw.setEnabled(true);
            }
            else
            {
                DateFormat formatter ;
                formatter = new SimpleDateFormat("dd-MMM-yy");    
                txtInactivDate.setText(formatter.format(UserActiu.getInactivationDate()));
                txtInactivUs.setText(UserActiu.getInactivationUser());
                txtInactivDate.setVisible(true);
                txtInactivUs.setVisible(true);
                lblIncactive.setVisible(true);
                btnModif.setEnabled(false);
                btnDelete.setEnabled(false);
                btnChangePw.setEnabled(false);
            } 
            
        }
        } catch (RemoteException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
	}   
}

    
    /***************************************************************************
     *   BTN - NOU USUARI
     ****************************************************************************/
    private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewActionPerformed
        //habilitem els objectes texts per a l'entrada de dadaes
        EnableObjects(true);
        //Netejem objectes de txt
        CleanTxt();
        NewUser = true;
        btnNew.setEnabled(false);
        btnModif.setEnabled(false);
        btnDelete.setEnabled(false);
        btnChangePw.setEnabled(false);
        btnSave.setEnabled(true);
        btnCancel.setEnabled(true);
        btnBack.setEnabled(true);
        tblUsers.setEnabled(false);
    }//GEN-LAST:event_btnNewActionPerformed

    /***************************************************************************
     *   BTN - Modificar usuari seleccionat del Grid
     ****************************************************************************/
    private void btnModifActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModifActionPerformed
        EnableObjects(true);
        btnModif.setEnabled(false);
        btnChangePw.setEnabled(false);
        btnNew.setEnabled(false);
        btnCancel.setEnabled(true);
        btnSave.setEnabled(true);
        tblUsers.setEnabled(false);
        txtUserId.setEnabled(false);
        txtPassword1.setEnabled(false);
        txtPassword2.setEnabled(false);
    }//GEN-LAST:event_btnModifActionPerformed

private void SaveNewPassw() throws RemoteException, edu.uoc.tdp.common.EIssueException{
    try {
            //remoto = new ManagementUsers();
            Client.remoteMaintenance.SavePassword(txtUserId.getText(),String.valueOf(txtPassword1.getPassword()));
            btnChange.setVisible(false);
            ObjectsStartStatus();
        } catch (RemoteException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
		} 
}    

private void InactivateUser() throws RemoteException, edu.uoc.tdp.common.EIssueException{
    try {
            //remoto = new ManagementUsers();
            Client.remoteMaintenance.SaveInactivationUser(UsuarioActivo,txtUserId.getText());
            ObjectsStartStatus();
        } catch (RemoteException ex) {
            Logger.getLogger(PanelResource.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelResource.class.getName()).log(Level.SEVERE, null, ex);
	} 
} 
  
public boolean PasswordCorrecto() {  
   
       boolean esCorrecto = true;  
       char[] clave1 = txtPassword1.getPassword();
       char[] clave2 = txtPassword2.getPassword();
       if (clave1.length==0){
           esCorrecto = false;  
       }
       else{
           if (clave1.length != clave1.length) {
               esCorrecto = false;  
           } else {  
               esCorrecto = Arrays.equals(clave1, clave2);  
           }             
           
       }
       return esCorrecto;  
}  


    /***************************************************************************
     *   BTN - GUARDAR
     ****************************************************************************/
    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed

        try {

            boolean DataOk = true;
            String TxtErr = null;

            if ((NewUser) && (PasswordCorrecto()==false)) {
                DataOk = false;
                TxtErr = "Password";
            }
            if ((NewUser) && txtUserId.getText().length() < 3) {
                DataOk = false;
                TxtErr = "LengthUserID";
                txtUserId.setBackground(Color.red);
            }
            if (txtName.getText().length() < 3) {
                DataOk = false;
                TxtErr = "LengthName";
                txtName.setBackground(Color.red);
            }
            
            try{
                if (Double.parseDouble(txtZipCode.getText()) <= 0) {
                    DataOk = false;
                    TxtErr = "ZipCode";
                    txtZipCode.setBackground(Color.red);
                }            
            }
            catch(NumberFormatException ex){  
                DataOk = false;
                txtZipCode.setBackground(Color.red);
            } 
            
            if (txtEmail.getText().length() < 6) {
                DataOk = false;
                TxtErr = "email";
                txtEmail.setBackground(Color.red);
            }        
            if (txtEmail.getText().contains("@") == false) {
                DataOk = false;
                TxtErr = "email";
                txtEmail.setBackground(Color.red);
            }
            if (txtEmail.getText().contains(".") == false) {
                DataOk = false;
                TxtErr = "email";
                txtEmail.setBackground(Color.red);
            }
            
            try {
                if ((NewUser) && Client.remoteMaintenance.CheckExistsUser(txtUserId.getText())) {
                    DataOk = false;
                    TxtErr = "Duplicate ID";
                    txtUserId.setBackground(Color.red);
                    JOptionPane.showMessageDialog(this, "Error! Ya existe un usuario esta ID" , "Error", JOptionPane.ERROR_MESSAGE);                
                }
            } catch (RemoteException ex) {
                Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) {
                Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            }  
            
            if (DataOk) {

                String user_id = txtUserId.getText();
                String password = String.valueOf(txtPassword1.getPassword());
                String name = txtName.getText();
                String surname1 = txtSurname1.getText();
                String surname2 = txtSurname2.getText();
                String company = txtCompany.getText();
                String address = txtAddress.getText();
                Integer postal_code = Integer.parseInt(txtZipCode.getText());
                String city = txtCity.getText();
                Integer telephone = Integer.parseInt(txtTelephone.getText());
                Integer mobile_phone = Integer.parseInt(txtMobile.getText());
                Integer roleid = cbRoles.getSelectedIndex();
                String email = txtEmail.getText();
                Date d1 = new Date();
                Date creation_date = new Date(d1.getDate());
                String creation_user = UsuarioActivo;

                UsuarioTrabajo = new User(user_id, password, name, surname1, surname2, company, address, postal_code, city, telephone, mobile_phone, roleid, email, creation_date, creation_user, null, null, null);

                boolean result = false;

                try {
                    if (NewUser) {
                        result = Client.remoteMaintenance.SaveUser(UsuarioTrabajo);
                    } else {
                        result = Client.remoteMaintenance.SaveUserChanges(UsuarioTrabajo);
                    }
                    if (result){
                        ObjectsStartStatus();
                        cargarGrid();
                    }
                    else{
                        JOptionPane.showMessageDialog(this, "Error al guardar los datos", "Error", JOptionPane.ERROR_MESSAGE);
                    }
                } catch (RemoteException ex) {
                    Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
                } catch (edu.uoc.tdp.common.EIssueException ex) {
                    Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
		}   


            } else {
                JOptionPane.showMessageDialog(this, "Datos incorrectos!" , "Error", JOptionPane.ERROR_MESSAGE);
            }

        } catch (MissingResourceException e) {
            
        }

    }//GEN-LAST:event_btnSaveActionPerformed



    /***************************************************************************
     *   BTN - ELIMINAR
     ****************************************************************************/
    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        if (tblUsers.getSelectedRow() > 0) {
            int resp=JOptionPane.showConfirmDialog(null, "Confirma que desea eliminar este usuario?","Eliminar",JOptionPane.YES_NO_OPTION);
            if (resp==JOptionPane.YES_OPTION)try {
                InactivateUser();
            } catch (RemoteException ex) {
                Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) {
                Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            }    
        }
    }//GEN-LAST:event_btnDeleteActionPerformed


    
    /***************************************************************************
     *   BTN - CANCELAR
     ****************************************************************************/
    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        ObjectsStartStatus();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnChangePwActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangePwActionPerformed
        EnableObjects(false);
        btnModif.setEnabled(false);
        btnChangePw.setEnabled(false);
        btnNew.setEnabled(false);
        btnCancel.setEnabled(true);
        btnSave.setEnabled(false);
        tblUsers.setEnabled(false);
        txtPassword1.setEnabled(true);
        txtPassword2.setEnabled(true);
        txtPassword1.setText("");
        txtPassword2.setText("");
        btnChange.setVisible(true);
    }//GEN-LAST:event_btnChangePwActionPerformed



    private void tblUsersMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblUsersMouseClicked
         
        //if (tblUsers.getSelectedRow() > 0) {
            int fila = tblUsers.rowAtPoint(evt.getPoint());
            int columna = tblUsers.columnAtPoint(evt.getPoint());
            if ((fila > -1) && (columna > -1)) {
            try {
                ShowUser(String.valueOf(tblUsers.getValueAt(fila, 0)));
            } catch (RemoteException ex) {
                Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) {
                Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_tblUsersMouseClicked

    private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed
        this.dispose(); //eliminar la referencia a memoria del form
    }//GEN-LAST:event_btnBackActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DialogLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DialogLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DialogLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DialogLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new PanelUser(Boolean.TRUE).setVisible(true);
                } catch (RemoteException ex) {
                    Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
                } catch (edu.uoc.tdp.common.EIssueException ex) {
                    Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
                }


            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        btnDelete = new javax.swing.JButton();
        btnNew = new javax.swing.JButton();
        btnModif = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        jPanelIni = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblUsers = new javax.swing.JTable();
        lblFind1 = new javax.swing.JLabel();
        cbFind1 = new javax.swing.JComboBox();
        btnFind = new javax.swing.JButton();
        lblFindValue = new javax.swing.JLabel();
        lblUserId = new javax.swing.JLabel();
        txtUserId = new javax.swing.JTextField();
        lblPassword = new javax.swing.JLabel();
        txtPassword1 = new javax.swing.JPasswordField();
        txtPassword2 = new javax.swing.JPasswordField();
        lblName = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        lblSurname1 = new javax.swing.JLabel();
        lblSurname2 = new javax.swing.JLabel();
        txtSurname2 = new javax.swing.JTextField();
        txtSurname1 = new javax.swing.JTextField();
        lblCompany = new javax.swing.JLabel();
        txtCompany = new javax.swing.JTextField();
        lblAddress = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        lblPostalCode = new javax.swing.JLabel();
        txtZipCode = new javax.swing.JTextField();
        txtTelephone = new javax.swing.JTextField();
        lblTelephone = new javax.swing.JLabel();
        lblCity = new javax.swing.JLabel();
        txtCity = new javax.swing.JTextField();
        lblMobile = new javax.swing.JLabel();
        txtMobile = new javax.swing.JTextField();
        lblEmail = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        cbRoles = new javax.swing.JComboBox();
        lblRoleId = new javax.swing.JLabel();
        lblInfo = new javax.swing.JLabel();
        btnChange = new javax.swing.JButton();
        txtFindValue = new javax.swing.JTextField();
        lblIncactive = new javax.swing.JLabel();
        txtInactivUs = new javax.swing.JTextField();
        txtInactivDate = new javax.swing.JTextField();
        lblUser = new javax.swing.JLabel();
        btnChangePw = new javax.swing.JButton();
        btnBack = new javax.swing.JButton();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Users");

        btnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/user_delete.png"))); // NOI18N
        btnDelete.setText("Delete");
        btnDelete.setMaximumSize(new java.awt.Dimension(71, 26));
        btnDelete.setMinimumSize(new java.awt.Dimension(71, 26));
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/user_add.png"))); // NOI18N
        btnNew.setText("Add");
        btnNew.setMaximumSize(new java.awt.Dimension(71, 26));
        btnNew.setMinimumSize(new java.awt.Dimension(71, 26));
        btnNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewActionPerformed(evt);
            }
        });

        btnModif.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/user_edit.png"))); // NOI18N
        btnModif.setText("Modif");
        btnModif.setMaximumSize(new java.awt.Dimension(71, 26));
        btnModif.setMinimumSize(new java.awt.Dimension(71, 26));
        btnModif.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModifActionPerformed(evt);
            }
        });

        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/cancel.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.setMaximumSize(new java.awt.Dimension(71, 26));
        btnCancel.setMinimumSize(new java.awt.Dimension(71, 26));
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/accept.png"))); // NOI18N
        btnSave.setText("Save");
        btnSave.setMaximumSize(new java.awt.Dimension(71, 26));
        btnSave.setMinimumSize(new java.awt.Dimension(71, 26));
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        jPanelIni.setBackground(new java.awt.Color(255, 255, 255));
        jPanelIni.setMaximumSize(new java.awt.Dimension(800, 600));
        jPanelIni.setMinimumSize(new java.awt.Dimension(637, 566));

        tblUsers.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "UserId", "Name", "Surname1", "Surname2", "Company", "PostalCode"
            }
        ));
        tblUsers.setColumnSelectionAllowed(true);
        tblUsers.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblUsersMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblUsers);
        tblUsers.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblUsers.getColumnModel().getColumn(0).setResizable(false);
        tblUsers.getColumnModel().getColumn(0).setPreferredWidth(80);
        tblUsers.getColumnModel().getColumn(1).setResizable(false);
        tblUsers.getColumnModel().getColumn(1).setPreferredWidth(80);
        tblUsers.getColumnModel().getColumn(2).setResizable(false);
        tblUsers.getColumnModel().getColumn(2).setPreferredWidth(120);
        tblUsers.getColumnModel().getColumn(3).setResizable(false);
        tblUsers.getColumnModel().getColumn(3).setPreferredWidth(120);
        tblUsers.getColumnModel().getColumn(4).setResizable(false);
        tblUsers.getColumnModel().getColumn(4).setPreferredWidth(120);
        tblUsers.getColumnModel().getColumn(5).setResizable(false);
        tblUsers.getColumnModel().getColumn(5).setPreferredWidth(50);

        lblFind1.setText("Find Field");

        cbFind1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ID", "CodPostal", "Nom", "Empresa" }));

        btnFind.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/find.png"))); // NOI18N
        btnFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFindActionPerformed(evt);
            }
        });

        lblFindValue.setText("Value");

        lblUserId.setText("UserId");

        lblPassword.setText("Password");

        txtPassword1.setText("jPasswordField2");
        txtPassword1.setMinimumSize(new java.awt.Dimension(100, 20));

        txtPassword2.setText("jPasswordField3");
        txtPassword2.setMinimumSize(new java.awt.Dimension(100, 20));

        lblName.setText("Name");

        lblSurname1.setText("Surname1");

        lblSurname2.setText("Surname2");

        lblCompany.setText("Company");

        txtCompany.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCompanyActionPerformed(evt);
            }
        });

        lblAddress.setText("Adress");

        txtAddress.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtAddressActionPerformed(evt);
            }
        });

        lblPostalCode.setText("PostalCode");

        txtZipCode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtZipCodeActionPerformed(evt);
            }
        });

        txtTelephone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTelephoneActionPerformed(evt);
            }
        });

        lblTelephone.setText("Telephone");

        lblCity.setText("City");

        txtCity.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCityActionPerformed(evt);
            }
        });

        lblMobile.setText("Mobile");

        txtMobile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMobileActionPerformed(evt);
            }
        });

        lblEmail.setText("email");

        txtEmail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEmailActionPerformed(evt);
            }
        });

        lblRoleId.setText("RodeID");

        lblInfo.setForeground(new java.awt.Color(255, 255, 255));
        lblInfo.setText("INFO");

        btnChange.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/accept.png"))); // NOI18N
        btnChange.setText("Save");
        btnChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChangeActionPerformed(evt);
            }
        });

        lblIncactive.setText("Intactive!");

        txtInactivUs.setBackground(new java.awt.Color(255, 51, 51));
        txtInactivUs.setForeground(new java.awt.Color(255, 255, 255));

        txtInactivDate.setBackground(new java.awt.Color(255, 51, 51));
        txtInactivDate.setForeground(new java.awt.Color(255, 255, 255));

        lblUser.setForeground(new java.awt.Color(0, 51, 255));
        lblUser.setText("USER");
        lblUser.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        javax.swing.GroupLayout jPanelIniLayout = new javax.swing.GroupLayout(jPanelIni);
        jPanelIni.setLayout(jPanelIniLayout);
        jPanelIniLayout.setHorizontalGroup(
            jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelIniLayout.createSequentialGroup()
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelIniLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelIniLayout.createSequentialGroup()
                                .addGap(100, 100, 100)
                                .addComponent(txtUserId, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanelIniLayout.createSequentialGroup()
                                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(lblPassword)
                                    .addComponent(lblName)
                                    .addComponent(lblSurname1)
                                    .addComponent(lblSurname2)
                                    .addComponent(lblCompany)
                                    .addComponent(lblAddress)
                                    .addComponent(lblTelephone)
                                    .addComponent(lblEmail)
                                    .addComponent(lblRoleId)
                                    .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lblUserId, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(lblPostalCode)))
                                .addGap(27, 27, 27)
                                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtZipCode, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtTelephone, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(cbRoles, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(txtCompany, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtSurname1, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtSurname2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                                        .addComponent(txtName)
                                        .addComponent(txtAddress, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)
                                        .addGroup(jPanelIniLayout.createSequentialGroup()
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
                                            .addComponent(lblCity)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(jPanelIniLayout.createSequentialGroup()
                                                    .addComponent(lblMobile)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(txtMobile, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addComponent(txtCity, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelIniLayout.createSequentialGroup()
                                            .addComponent(txtPassword1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(57, 57, 57)
                                            .addComponent(txtPassword2, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(18, 18, 18)
                                            .addComponent(btnChange, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(txtEmail, javax.swing.GroupLayout.Alignment.LEADING))))))
                    .addGroup(jPanelIniLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelIniLayout.createSequentialGroup()
                                .addComponent(lblFind1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(39, 39, 39)
                                .addComponent(cbFind1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblFindValue)
                                .addGap(18, 18, 18)
                                .addComponent(txtFindValue, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27)
                                .addComponent(btnFind, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 120, Short.MAX_VALUE)
                                .addComponent(lblUser, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanelIniLayout.createSequentialGroup()
                                .addComponent(lblInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 322, Short.MAX_VALUE)
                                .addComponent(lblIncactive)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtInactivUs, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtInactivDate, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 723, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(16, Short.MAX_VALUE))
        );
        jPanelIniLayout.setVerticalGroup(
            jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelIniLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblFind1)
                        .addComponent(cbFind1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblFindValue)
                        .addComponent(txtFindValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnFind, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblUser))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtInactivUs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblIncactive)
                    .addComponent(txtInactivDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblInfo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUserId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblUserId))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanelIniLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPassword1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtPassword2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblPassword)))
                    .addComponent(btnChange, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(18, 18, 18)
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSurname1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSurname1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSurname2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSurname2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCompany, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCompany))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAddress))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelIniLayout.createSequentialGroup()
                        .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtZipCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblPostalCode))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtTelephone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMobile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblTelephone)
                            .addComponent(lblMobile))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblCity)))
                .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelIniLayout.createSequentialGroup()
                        .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelIniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbRoles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblRoleId)))
                    .addComponent(lblEmail))
                .addGap(28, 28, 28))
        );

        btnChangePw.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/application_key.png"))); // NOI18N
        btnChangePw.setText("Change password");
        btnChangePw.setMaximumSize(new java.awt.Dimension(71, 26));
        btnChangePw.setMinimumSize(new java.awt.Dimension(71, 26));
        btnChangePw.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChangePwActionPerformed(evt);
            }
        });

        btnBack.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/door_out.png"))); // NOI18N
        btnBack.setText("Back");
        btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(btnCancel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnSave, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnChangePw, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnDelete, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnModif, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnNew, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE))
                    .addComponent(btnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnNew, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnModif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addComponent(btnChangePw, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnBack)
                        .addGap(50, 50, 50))))
        );
    }// </editor-fold>//GEN-END:initComponents

private void txtCompanyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCompanyActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtCompanyActionPerformed

private void txtZipCodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtZipCodeActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtZipCodeActionPerformed

private void txtMobileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMobileActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtMobileActionPerformed

private void txtEmailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEmailActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtEmailActionPerformed

private void txtCityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCityActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtCityActionPerformed

private void txtTelephoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTelephoneActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtTelephoneActionPerformed

private void txtAddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtAddressActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtAddressActionPerformed

    private void btnChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangeActionPerformed

        String a=null;
        if (PasswordCorrecto()) {
                 int resp=JOptionPane.showConfirmDialog(null, "Confirma el cambio?","Eliminar",JOptionPane.YES_NO_OPTION);
                 if (resp==JOptionPane.YES_OPTION)try {
                SaveNewPassw();
            } catch (RemoteException ex) {
                Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) {
                Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            }    
            }
        else{
                JOptionPane.showMessageDialog(this,TDPLanguageConstants.CLIENT_PANELUSER_MSGPASSWORD,"Error",JOptionPane.ERROR_MESSAGE);                 
            }
    }//GEN-LAST:event_btnChangeActionPerformed


        
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBack;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnChange;
    private javax.swing.JButton btnChangePw;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnFind;
    private javax.swing.JButton btnModif;
    private javax.swing.JButton btnNew;
    private javax.swing.JButton btnSave;
    private javax.swing.JComboBox cbFind1;
    private javax.swing.JComboBox cbRoles;
    private javax.swing.JPanel jPanelIni;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lblAddress;
    private javax.swing.JLabel lblCity;
    private javax.swing.JLabel lblCompany;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblFind1;
    private javax.swing.JLabel lblFindValue;
    private javax.swing.JLabel lblIncactive;
    private javax.swing.JLabel lblInfo;
    private javax.swing.JLabel lblMobile;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblPostalCode;
    private javax.swing.JLabel lblRoleId;
    private javax.swing.JLabel lblSurname1;
    private javax.swing.JLabel lblSurname2;
    private javax.swing.JLabel lblTelephone;
    private javax.swing.JLabel lblUser;
    private javax.swing.JLabel lblUserId;
    private javax.swing.JTable tblUsers;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtCity;
    private javax.swing.JTextField txtCompany;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFindValue;
    private javax.swing.JTextField txtInactivDate;
    private javax.swing.JTextField txtInactivUs;
    private javax.swing.JTextField txtMobile;
    private javax.swing.JTextField txtName;
    private javax.swing.JPasswordField txtPassword1;
    private javax.swing.JPasswordField txtPassword2;
    private javax.swing.JTextField txtSurname1;
    private javax.swing.JTextField txtSurname2;
    private javax.swing.JTextField txtTelephone;
    private javax.swing.JTextField txtUserId;
    private javax.swing.JTextField txtZipCode;
    // End of variables declaration//GEN-END:variables
}

class TableModelUser extends AbstractTableModel {

    List UsersList;
    //String headerList[] = new String[]{"user_id", "name", "surname1", "surname2", "company", "postal_code"};
    String headerList[] = new String[]{"Id", "Name", "Surname1", "Surname2", "Company", "Postal Code"};

    public TableModelUser(List list) {
        UsersList = list;
    }

    @Override
    public int getColumnCount() {
        return 6;
    }

    @Override
    public int getRowCount() {
        return UsersList.size();
    }
    // this method is called to set the value of each cell

    @Override
    public Object getValueAt(int row, int col) {
        Object returnValue = false;
        //User entity = null;
        User entity = (User) UsersList.get(row);
        switch (col) {
            case 0:
                returnValue = entity.getUserId();
                break;
            case 1:
                returnValue = entity.getName();
                break;
            case 2:
                returnValue = entity.getSurname1();
                break;
            case 3:
                returnValue = entity.getSurname2();
                break;
            case 4:
                returnValue = entity.getCompany();
                break;
            case 5:
                returnValue = entity.getPostalCode();
                break;
        }
        return returnValue;
    }
    //display the name of columns

    @Override
    public String getColumnName(int col) {
        return headerList[col];
    }
}